function price=mcprice
Npath = 50000;
X = 0; K=1;
for ii=1:Npath
    X = X+max(getaX-K,0);
    disp(ii);
end

price = X/Npath;
end

function XT=getaX

eps=0.01; az=1; bz=1; mz=1; my=1; rho=0.5; t=0; T=0.5; by=1; ay=1/eps; v=sqrt(by^2/2/ay); r=0;

X=zeros(5001,1); Y=X; Z=X;
Y(1)=1; Z(1)=1; dt = (T-t)/5000;

for ii=2:5001
    w0 = rand(1); w1hat = rand(1); w2 = rand(1); w1 = rho*w0+sqrt(1-rho^2)*w1hat;
    Y(ii) = 1/eps*(my-Y(ii-1))*dt +v*sqrt(2)/sqrt(eps)*sqrt(dt)*w1;
    Z(ii) = az*(mz-Z(ii-1))*dt+bz*sqrt(dt)*w2;
    X(ii) = r*X(ii-1)*dt+Y(ii-1)*Z(ii-1)*X(ii-1)*sqrt(dt)*w0;
end
XT=X(5001);
end

